import Vue from "vue";
import Vuex from "vuex";
import videoStore from "./module/video";
Vue.use(Vuex);
import { _getUserInfo } from "../api/home";
export default new Vuex.Store({
    state: {
        user: {}, //用户信息
        dirID: "", //当前选中的目录id
    },
    mutations: {
        changeUser(state, obj) {
            //存储用户信息
            state.user = obj;
            localStorage.user = JSON.stringify(obj);
        },
        // 改变当前选择的目录id
        changeDirId(state, id) {
            state.dirID = id;
        },
    },
    actions: {
        // 获取用户信息接口
        async userAction({ commit }) {
            // 获取用户信息接口
            var res = await _getUserInfo();
            console.log(res);
            commit("changeUser", res);
        },
    },
    getters: {
        user: (state) => {
            if (localStorage.user) {
                return JSON.parse(localStorage.user);
            } else {
                return state.user;
            }
        },
    },
    modules: {
        //分模块
        videoStore,
    },
});